import br.com.nooclix.salon.ui.dto.attendance.AttendanceSheetBusyTO;
import br.com.nooclix.salon.ui.dto.attendance.AttendanceSheetTO;
import br.com.nooclix.salon.ui.dto.customer.CustomerTO;
import br.com.nooclix.salon.ui.screen.CenterPanel;
import br.com.nooclix.salon.ui.util.ResponseData;
import br.com.nooclix.salon.ui.util.WindowsMessage;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

protected var attBusy:ArrayCollection;
protected var attendanceBusy:AttendanceSheetBusyTO;
protected var returnBusy:ArrayCollection;

public function findByNameResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	
	if(responseData.status == ResponseData.ok()){
		cbCustomer.dataProvider = responseData.items;
		
	}else{
		WindowsMessage.alarm(responseData.message);
	}
}

private function persistResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	
	if(responseData.status == ResponseData.ok()){
		WindowsMessage.confirm("Atendimento salvo com sucesso!");
		
	}
}

private function findBookingByStatusResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	
	if(responseData.status == ResponseData.ok()){
		bookingByStatusList = responseData.items;
		gridAttendanceSheet.dataProvider = responseData.items;
	}else{
		WindowsMessage.alarm(responseData.message);
	}
}

private function removeAttendanceSheetResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	
	if(responseData.status == ResponseData.ok()){
		gridAttendanceSheet.dataProvider = responseData.items;
	}else{
		WindowsMessage.alarm(responseData.message);
	}
}
private function updateAttendanceSheetResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	
	if(responseData.status == ResponseData.ok()){
		WindowsMessage.confirm("Atendimento finalizado com sucesso!");
		findBookingByStatusController();
	}else{
		WindowsMessage.alarm(responseData.message);
	}
}
private function alterAttendanceSheetResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	
	if(responseData.status == ResponseData.ok()){
		WindowsMessage.confirm("Operação realizada com sucesso!");
		//clearFields();
	}else{
		WindowsMessage.alarm(responseData.message);
	}
}
private function cancelAttendanceSheetResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	
	if(responseData.status == ResponseData.ok()){
		WindowsMessage.confirm("Atendimento cancelado com sucesso!");
		findBookingByStatusController();
	}else{
		WindowsMessage.alarm(responseData.message);
	}
}
	
private function findBusyEmployeeResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	//returnBusy = new ArrayCollection();
	if(responseData.status == ResponseData.ok()){
		/*attBusy = responseData.items;
		for each(var busy:AttendanceSheetBusyTO in attBusy){
				if(returnBusy == null){
					returnBusy.addItem(busy);
			}
			for each(var att:AttendanceSheetBusyTO in returnBusy){
			if(att.employee.person.name != busy.employee.person.name && att.hour != busy.hour){
				returnBusy.addItem(att);
			}			
		}*/
		gridBusyEmployee.dataProvider = responseData.items;
	}else{
		WindowsMessage.alarm(responseData.message);
	
	}
}
